package com.gec;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

import java.util.HashMap;

public class DuanxinCeshi {
    public static void main(String[] args) {
        //连接阿里云
        DefaultProfile profile = DefaultProfile.getProfile("cn-guangzhou", "LTAI5tEFBQRfsPdcduLeR4SL", "nZmi4EUdP150ffMVbMkhwbW20FrxoQ");
        IAcsClient client = new DefaultAcsClient(profile);

        //构建请求，一般这里不用动
        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");

        //设置发送相关的参数
        request.putQueryParameter("RegionId", "cn-guangzhou");
        request.putQueryParameter("PhoneNumbers","13299259007"); //手机号
        request.putQueryParameter("SignName","小宇物业管理系统"); //申请阿里云 签名名称
        request.putQueryParameter("TemplateCode","SMS_464220772"); //申请阿里云 模板code

        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 123456);
        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));//验证码数据，转换json数据传递

        try{
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ClientException e){
            e.printStackTrace();
        }
    }
}
